package com.testmall.controller;

import com.testmall.entity.Orders;
import com.testmall.entity.common.PageBean;
import com.testmall.entity.common.ResultBean;
import com.testmall.mapper.OrdersMapper;
import com.testmall.service.OrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: k23
 * @Date: 2022-06-23 9:41
 * @Version: 1.0
 */
@RestController
@RequestMapping("/api/order")
@Api(value = "订单接口", tags = "订单接口")
public class OrdersController extends BaseController {

        @Autowired
        OrdersService Ordersservice;

        @Autowired
        OrdersMapper ordersMapper;


        @PostMapping("/save")
        @ApiOperation(value = "生成订单",
                notes = "detail[0].userid(订单详情用户id)必须传值," +
                        "userid(订单用户id)必须传值," +
                        "proid(分类id)必须传值")
        public ResultBean save(@RequestBody Orders orders) {
                int rs = Ordersservice.mainsaveOrders(orders);
                return rs > 0 ? success("下单成功") : fail("下单失败");
        }


        @PostMapping("/query")
        @ApiOperation(value = "订单列表",
                notes = "根据时间段查询订单，" +
                        "根据订单id,用户id,状态查询订单")
        public ResultBean queryOrder(@RequestBody Map map) {
                PageBean bean = Ordersservice.query(map);
                return success("订单列表", bean);

        }

        @PostMapping("/queryorderdetail")
        @ApiOperation(value = "订单详情列表",
                notes = "")
        public ResultBean queryOrderDetail(String id) {
                List orders = Ordersservice.queryOrdersDetail(id);
                return success("订单详情", orders);
        }

        @PostMapping("/querymember")
        @ApiOperation(value = "查询会员订单列表", notes = "查询会员订单列表")
        public List<Orders> queryMemberOrder() {
                return Ordersservice.querymemberCategory();
        }







}
